class MigratePages < ActiveRecord::Migration

  class << self
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Database create/drop methods
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def up
      create_folders_table
      create_pages_table
    end

    def down
      drop_pages_table
      drop_folders_table
    end

    private
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      # Table create/drop methods
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
      def create_folders_table
        create_table_with_history(:folders, :force => true) do |t|
          t.column("name", :text)
          t.column("parent_id", :integer)
          t.column("seq", :integer, :default => 1)
          t.column("updated_by", :integer, :null => false)
          t.column("updated_at", :datetime)
        end

        foreign_key(:folders, :parent_id, :folders)
        foreign_key(:folders, :updated_by, :updaters)
      end

      def drop_folders_table
        drop_table_with_history(:folders)
      end

      def create_pages_table
        create_table_with_history(:pages, :force => true) do |t|
          t.column("folder_id", :integer)
          t.column("title", :text, :null => false)
          t.column("content", :text)
          t.column("is_private", :boolean, :default => false)
          t.column("is_featured", :boolean, :default => false)
          t.column("updated_by", :integer, :null => false)
          t.column("updated_at", :datetime)
        end

        foreign_key(:pages, :folder_id, :folders)
        foreign_key(:pages, :updated_by, :updaters)
      end
    
      def drop_pages_table
        drop_table_with_history(:pages)
      end
  end #end class block
end
